<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitUpdate9 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('coupons', function (Blueprint $table) {

            $table->dropColumn('transfered_total');
            $table->dropColumn('total');

            $table->boolean('is_shareable')->default(1)->comment('0为不可分享 1为可分享');

            $table->integer('score_price')->unsigned()->nullable()->comment('积分兑换价格'); 
            $table->integer('money_price')->unsigned()->nullable()->comment('人民币价格'); 

            $table->integer('stock')->unsigned()->nullable()->comment('库存'); // 数量
            $table->integer('sales')->unsigned()->default(0)->index()->comment('销量'); // 已抽次数

            $table->integer('sale_by_code')->unsigned()->default(0)->index()->comment('兑换码发放'); // 已抽次数
            $table->integer('sale_by_manual')->unsigned()->default(0)->index()->comment('页面中手动领取'); // 已抽次数
            $table->integer('sale_by_system')->unsigned()->default(0)->index()->comment('系统发放'); // 已抽次数
        });

        Schema::table('coupon_user', function (Blueprint $table) {
            $table->tinyInteger('sale_type')->index()->default(1)->comment('1为兑换码问的、 2为手动领取、 3为系统发放');
        });

        Schema::table('order_skus', function (Blueprint $table) {
            $table->integer('product_id')->nullable()->comment('所属商品id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('coupons', function (Blueprint $table) {
            $table->dropColumn('is_shareable');
            $table->dropColumn('score_price');
            $table->dropColumn('money_price');
            $table->dropColumn('stock');
            $table->dropColumn('sales');
            $table->dropColumn('sale_by_code');
            $table->dropColumn('sale_by_manual');
            $table->dropColumn('sale_by_system');
        });

        Schema::table('coupon_user', function (Blueprint $table) {
            $table->dropColumn('sale_type');
        });

        Schema::table('order_skus', function (Blueprint $table) {
            $table->dropColumn('product_id');
        });
    }
}
